const JwtStrategy = require('passport-jwt').Strategy;
const ExtractJwt = require('passport-jwt').ExtractJwt;
const model = require('../models/Users');
// const modelUsers = model.getModle("users");
// const mongoose = require("mongoose");
// const User = mongoose.model("users");    

const keys = require("./index");
const opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken(); //通过配置信息来生成jwt的请求，验证这个token
opts.secretOrKey = keys.secretOrKey;

module.exports = passport => {
    passport.use(new JwtStrategy(opts, function (jwt_payload, done) {
        console.log(jwt_payload); //jwt_payload就是用户信息
        // modelUsers.findById(jwt_payload.id)
        //     .then(user => {
        //         if (user) {
        //             return done(null, user);
        //         }
        //         return done(null, false);
        //     })
        //     .catch(err => console.log(err));
    }));
}